package logic.enemies;

import java.util.ArrayList;

import logic.blocks.Block;
import logic.characters.Crash;
import logic.characters.Jigglypuff;
import logic.characters.Player;
import logic.characters.Samus;
import logic.characters.Snake;
import logic.pruebas.GamePanel;

public class Goomba extends Enemy{
	private static final long serialVersionUID = -7796864718899201700L;

	public Goomba(float x, float y, GamePanel panel, String nomImg, int difficulty, ArrayList<Enemy> enemies, ArrayList<Block> blocks, Player player) {
		super(x, y, panel, nomImg, difficulty, enemies, blocks, player);
		attack = 9;
		defense = 6;
		magic = 0;
		resistance = 4;
		experience = 1;
		life = 18;
		jump = 3;
		speed = 8;
		velX = -speed * 20;
		life = life * difficulty;
		attack = attack * difficulty;
		defense = defense * difficulty;
		magic = magic * difficulty;
		resistance = resistance * difficulty;
		originalSpeed = speed;
		originalJump = jump;
		experience = experience * difficulty;
	}

	@Override
	public void upImpact(Player player) {
		if ((player instanceof Snake || player instanceof Samus) && player.special) {
			player.specialEffect(this);
		} else {
		player.damage(attack);
		jump();
		}
		
	}

	@Override
	public void downImpact(Player player) {
		if ((player instanceof Snake || player instanceof Samus) && player.special) {
			player.specialEffect(this);
		} else {
		player.falling = false;
		player.onPlatform = true;
		player.velY = 0;
		player.coorY = coorY - player.altura - 1;
		player.jumping= false;
		player.jump();
		this.damage(defense + 1);
		}
		
	}

	@Override
	public void rightImpact(Player player) {
		if (player.attacking && player.lookingRight) {
			damage(player.attack);
			velX = -velX;
			coorX = player.collisionX + player.collisionWidth + 1;
		} else if (player.special){
			if (player instanceof Crash || player instanceof Jigglypuff || player instanceof Samus || player instanceof Snake) {
				if (player instanceof Snake) {
					player.specialEffect(this);
				} else {
					player.specialEffect(this);
					coorX = player.collisionX + player.collisionWidth + 1;
				}
			} else if (player.lookingRight) {
				coorX = player.collisionX + player.collisionWidth + 1;
				player.specialEffect(this);
			}

		} else {
			player.damage(attack);
			velX = -velX;
			player.velX = 0;
			coorX = player.collisionX + player.collisionWidth + 1;
		}
		//jugador.velX = 0;
		
	}

	@Override
	public void leftImpact(Player player) {
		if (player.attacking && !player.lookingRight) {
			damage(player.attack);
			velX = -velX;
			coorX = player.collisionX - collisionWidth - 1;
		} else if (player.special) {
			if (player instanceof Crash || player instanceof Jigglypuff || player instanceof Samus || player instanceof Snake) {
				if (player instanceof Snake) {
					player.specialEffect(this);	
				} else {
					player.specialEffect(this);
					coorX = player.collisionX - collisionWidth - 1;
				}
			} else if (!player.lookingRight) {
				coorX = player.collisionX - collisionWidth - 1;
				player.specialEffect(this);
			}
		} else {
			player.damage(attack);
			velX = -velX;
			player.velX = 0;
			coorX = player.collisionX - collisionWidth - 1;
		}
		//jugador.velX = 0;
		
	}

	public void update(Player player) {
		if (!dead && !sleeping && relevant) {
		if (velX < 0) {
			updateIcon("resources/GoombaL.gif");
		} else if (velX > 0) {
			updateIcon("resources/GoombaR.gif");
		}
		
		if (velX < 0) {
			velX = -speed * 20;	
		} else if (velX > 0) {
			velX = speed * 20;
		}
		}
		super.update(player);
	}
}
